package com.zhx.threadcoreknowledge.synchromized;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-02 10:39
 * 用途         ： 类锁的第一种形式,static形式
 */
public class SynchonizedClassStatic4 implements Runnable{

    private static SynchonizedClassStatic4 instance1 = new SynchonizedClassStatic4();
    private static SynchonizedClassStatic4 instance2 = new SynchonizedClassStatic4();

    @Override
    public void run() {
        try {
            method();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(instance1);
        Thread thread2 = new Thread(instance2);
        thread1.start();
        thread2.start();

        while (thread1.isAlive() || thread2.isAlive()){

        }

        System.out.println("finashed");
    }

    public static synchronized void method() throws InterruptedException {
        System.out.println("我是对象锁的方法修饰符形式,我叫:"+Thread.currentThread().getName());
        Thread.sleep(3000);
        System.out.println(Thread.currentThread().getName()+"运行结束了");
    }
}
